Skip to content

auth: drop query and fragment from server URL for resource metadata - #1525

Closed
beiryu wants to merge 1 commit into
modelcontextprotocol:mainfrom
beiryu:fix-1519-auth-oauth-client-rejects-protected-reso
Closed

beiryu wants to merge 1 commit into
modelcontextprotocol:mainfrom
beiryu:fix-1519-auth-oauth-client-rejects-protected-reso

Conversation

@beiryu

@beiryu beiryu commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #1519

When the MCP server URL has a query string (for example https://mcp.example.com/mcp?features=flags), the OAuth client used the full URL, query included, to build the protected resource metadata candidates and to compare against the metadata's resource. A server that follows RFC 8707 section 2 publishes a resource without the query, so every candidate was rejected and the handler fell back to the server root.

AuthorizationCodeHandler.getProtectedResourceMetadata now clears the query and fragment from the server URL before it builds the well-known candidate URLs and before the resource comparison.

Testing: added TestGetProtectedResourceMetadata_QueryInServerURL in auth/authorization_code_test.go. It serves metadata whose resource has no query and checks that a server URL ending in ?features=flags is accepted. The new test and the auth package tests pass.

The OAuth client failed for MCP servers that put settings in the URL query, even when the server followed the RFC. I wanted this case to work like it does in the other official SDKs.

@github-actions github-actions Bot added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Nov 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been closed automatically. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and you aren't currently assigned to #1519.

You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned. There's no need to open a new PR either way.

Maintainers: reopen, remove missing-issue-link, or add bypass-issue-check to override.

@github-actions github-actions Bot closed this Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

auth: OAuth client rejects protected resource metadata when the MCP server URL has a query string

1 participant